<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户选择列表页')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
						<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="participators" name="participators" th:value="${participators}" >	
						<input type="hidden" id="deptId" name="deptId">
		                <input type="hidden" id="parentId" name="parentId">
		                <input type="hidden" id="status" name="status" value="0">
						<div class="select-list">
							<ul>
							<!-- 	<li>
									登录名称：<input type="text" name="loginName"/>
								</li> -->
								<li>
									员工姓名：<input type="text" name="userName"/>
								</li>
								<li>
									手机号码：<input type="text" name="phonenumber"/>
								</li>
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "system/user";
        var datas = [[${@dict.getType('sys_normal_disable')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        pageSize: 10,       
		        //height: 500,
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
                columns: [{
                	//field: 'state',
		            checkbox: true,
		            formatter:getRowIsCheck
		        },
				{
					field : 'userId', 
					title : '用户ID',
					 visible: false
				},
				{
					field : 'userName', 
					title : '用户姓名'
				},
				{
					field : 'phonenumber', 
					title : '用户手机'
				},
				{
					field : 'email', 
					title : '用户邮箱'
				},
				{
                    field: 'status',
                    title: '用户状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return $.table.selectDictLabel(datas, value);
                    }
                } ]
            };
            $.table.init(options);
        });
        
        //是否选中该用户
        function getRowIsCheck(value, row, index){
        	var participators = $('#participators').val();
        	var userIds = participators.split(",");
        	for(var i=0;i<userIds.length;i++){
        		if(userIds[i]==row.userId){
        			return {checked:true};
        		}
        		
        	}
        	//alert(participators);
        }
        
        /* 添加用户-选择用户-提交 */
		function submitHandler(index, layero) {
			//var rows = $.table.bootstrapTable('getSelections');
			var rows = $("#bootstrap-table").bootstrapTable('getSelections');
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
			$.modal.close();
			
			var resHtml ='';
			var userIds='';
			for(var i=0;i<rows.length;i++){
				resHtml +=rows[i].userName+',';
				userIds +=rows[i].userId+',';
			}
			//赋值父页面的变量
			parent.$('#participators').val(userIds);
			parent.$('#participators-view').html(resHtml);
		}
    </script>
</body>
</html>